<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
  <meta charset="UTF-8">
  <title>欢迎页面-X-admin2.0</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" href="manager/css/font.css">
  <link rel="stylesheet" href="manager/css/xadmin.css">
  <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script type="text/javascript" src="manager/lib/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="manager/js/xadmin.js"></script>
  <style>
    img{
      width: 100px;
      height: 60px;
    }
  </style>
  <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  <!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
  <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
  <xblock>
    <button shiro:hasPermission="/delProductCategory" class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
    <button shiro:hasPermission="/productCategoryAdd" class="layui-btn" onclick="x_admin_show('添加用户','productCategoryAdd',600,400)"><i class="layui-icon"></i>添加</button>
  </xblock>
  <table class="layui-table">
    <thead>
    <tr>
      <th>
        <input type="checkbox" name="ckAll" >
      </th>
      <th>ID</th>
      <th>产品分类名</th>
      <th>产品分类图片</th>
      <th>产品分类描述</th>
      <th shiro:hasPermission="/updProductCategoryStatus">状态</th>
      <th shiro:hasPermission="/delProductCategory,/updProductCategory,/ProductCategoryEdit" >操作</th>
    </thead>
    <tbody class="x-cate">
    <tr th:each="productCategory:${productCategorys}" th:attr="cate-id = ${productCategory.pc_id},fid = ${productCategory.ppc_id==null?0:productCategory.ppc_id}" >
      <td>
        <input type="checkbox" name="ck" th:value="${productCategory.pc_id}" >
      </td>
      <td th:text="${productCategory.pc_id}"></td>
      <td>
        <span th:if="${productCategory.pc_rank==2}">&nbsp;&nbsp;&nbsp;&nbsp;</span>
        <i class="layui-icon x-show" status='true'>&#xe623;</i>
        [[${productCategory.pc_name}]]
      </td>
      <td><img th:src="${productCategory.pc_image}"/></td>
      <td th:text="${productCategory.pc_desc}"></td>
      <td shiro:hasPermission="/updProductCategoryStatus">
        <div th:if="${productCategory.pc_status=='1'}" th:onclick="updStatus(this,'[[${productCategory.pc_id}]]')" class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em>开启</em><i></i></div>
        <div th:if="${productCategory.pc_status!='1'}" th:onclick="updStatus(this,'[[${productCategory.pc_id}]]')" class="layui-unselect layui-form-switch" lay-skin="_switch"><em>停用</em><i></i></div>
      </td>
      <td shiro:hasPermission="/delProductCategory,/updProductCategory,/ProductCategoryEdit" class="td-manage">
        <button shiro:hasPermission="/updProductCategory" class="layui-btn layui-btn layui-btn-xs"  th:onclick="x_admin_show('编辑','productCategoryEdit?pc_id=[[${productCategory.pc_id}]]')" ><i class="layui-icon">&#xe642;</i>编辑</button>
        <button shiro:hasPermission="/ProductCategoryEdit" th:if="${productCategory.pc_rank==1}" class="layui-btn layui-btn-warm layui-btn-xs"  th:onclick="x_admin_show('编辑','productCategoryAdd?pc_id=[[${productCategory.pc_id}]]')" ><i class="layui-icon">&#xe642;</i>添加子栏目</button>
        <button shiro:hasPermission="/delProductCategory" class="layui-btn-danger layui-btn layui-btn-xs"  th:onclick="member_del(this,'[[${productCategory.pc_id}]]')" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
      </td>
    </tr>
    </tbody>
  </table>
</div>
<style type="text/css">

</style>
<script>
  $("input[name='ckAll']").click(function () {
    $("input[name='ck']").prop("checked",$("input[name='ckAll']").prop("checked"))
  })
  $("input[name='ck']").click(function () {
    var ss = $("input[name='ck']").length==$("input[name='ck']:checked").length;
    $("input[name='ckAll']").prop("checked",ss)
  })

  /*用户-停用*/
  function updStatus(obj,id){
    layer.confirm('确定要'+($(obj).text()=="停用"?"启用":"停用")+'吗？',function(index){
      if($(obj).text()=="开启"){
        //发异步把用户;状态进行更改
        $.ajax({
          url:"updProductCategoryStatus",
          data:{"pc_id":id,"pc_status":2},
          type:"post",
          success:function (result) {
            if(result.result=="0000"){
              $(obj).attr("class","layui-unselect layui-form-switch")
              $(obj).html("<em>停用</em><i></i>")
              layer.msg("停用成功!",{icon:1,time:1000});
            }else{
              layer.msg("停用失败!",{icon:5,time:1000});
            }
          },
          error:function (result) {
            layer.msg('权限不够!',{icon:2,time:1000});
          },
          dataType:"json"
        })
      }else{
        $.ajax({
          url:"updProductCategoryStatus",
          data:{"pc_id":id,"pc_status":1},
          type:"post",
          success:function (result) {
            if(result.result=="0000"){
              $(obj).attr("class","layui-unselect layui-form-switch layui-form-onswitch")
              $(obj).html("<em>开启</em><i></i>")
              layer.msg("启用成功!",{icon:1,time:1000});
            }else{
              layer.msg("启用失败!",{icon:5,time:1000});
            }
          },
          error:function (result) {
            layer.msg('权限不够!',{icon:2,time:1000});
          },
          dataType:"json"
        })
      }
    });
  }

  /*用户-删除*/
  function member_del(obj,id){
    layer.confirm('确认要删除吗？',function(index){
      //发异步删除数据
      $.ajax({
        url:"delProductCategory",
        data:{"ids":id},
        type:"post",
        success:function (result) {
          console.info(result)
          if(result.result=="0000"){
            $(obj).parents("tr").remove();
            layer.msg('已删除!',{icon:1,time:1000});
          }else{
            layer.msg(result.resultMsg,{icon:2,time:1000});
          }
        },
        error:function (result) {
          layer.msg('权限不够!',{icon:2,time:1000});
        },
        dataType:"json"
      })
    });
  }


  function delAll (argument) {

    var data = tableCheck.getData();

    layer.confirm('确认要删除吗？'+data,function(index){
      //捉到所有被选中的，发异步进行删除
      cks = $("input[name='ck']:checked");
      var str = "";
      for (var i = 0; i < cks.length;i++){
        if(i == cks.length-1){
          str+=cks.eq(i).val();
        }else{
          str+=cks.eq(i).val()+",";
        }
      }
      $.ajax({
        url:"delProductCategory",
        data:{"ids":str},
        type:"post",
        success:function (result) {
          if(result.result=="0000"){
            layer.msg('删除成功', {icon: 1});
            location.reload();
          }else{
            layer.msg(result.resultMsg,{icon:1,time:1000});
          }
        },
        dataType:"json"
      })
    });
  }
</script>
</body>

</html>